<script setup lang="ts">
import {useMainStore} from "@/store/main";
import {useRouter} from "vue-router";
import {loginApi} from "@/service/api/login/login";

const admin = useMainStore()
const router = useRouter()
const updateName = async (name: string) => {
  // let obj = {
  //   userName: name,
  //   passWord: '123456'
  // }
  // axios.post('/api/login', obj).then(res => {
  //   console.log(res)
  // }).catch(err => {
  //   console.error(err)
  // })
  await admin.insertName(name)
  await loginApi.login({'userName': name, 'passWord': '123456'}).then(res => {
    console.log(res)
    router.push("/info")
  }).catch(err => {
    console.error(err)
    router.push("/info")
  })
}
</script>

<template>
  <el-container>
    <div class="text-red-500 block">{{ admin }}</div>
    <div>{{ admin.getName }}</div>
    {{ admin.nameLength }}
  </el-container>
  <el-input v-model="admin.name" style="width: 20%"></el-input>
  <el-button type="success" @click="updateName(admin.name)">更新名称</el-button>
</template>

<style scoped>
</style>
